package utils

import (
	"crypto/hmac"
	"crypto/sha1"
	"encoding/base64"
	"io"
	"rpcSrv/configs"
	"strings"
)

func GetShe1Base64ByKey(key string, strb []byte) string {
	if strings.TrimSpace(key) == "" {
		key = configs.GetSha1KeyConf()
	}
	k := []byte(key)
	mac := hmac.New(sha1.New, k)
	mac.Write(strb)
	return base64.StdEncoding.EncodeToString(mac.Sum(nil))
}

func GetShe1Base64(strb []byte) string {
	h := sha1.New()
	_, err := io.WriteString(h, string(strb))
	if CheckErr(err) {
		return ""
	}
	return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
